
#ifndef __RT_OBJECT_API_H__
#define __RT_OBJECT_API_H__

#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* End of #ifdef __cplusplus */

#include "rt_p2p_log.h"
#include "rt_p2p_types.h"
#include "rt_wakeup_query.h"

/*链接的网络信息结构体*/
typedef struct _RT_APP_NETWORK_Info_s{	
	RT_APP_CHAR bFlagInternet;		// Internet Reachable? 1: YES, 0: NO
	RT_APP_CHAR bFlagHostResolved;	// P2P Server IP resolved? 1: YES, 0: NO
	RT_APP_CHAR bFlagServerHello;	// P2P Server Hello? 1: YES, 0: NO
	RT_APP_CHAR NAT_Type;			// NAT type, 0: Unknow, 1: IP-Restricted Cone type,   2: Port-Restricted Cone type, 3: Symmetric 
	RT_APP_CHAR MyLanIP[16];		// My LAN IP. If (bFlagInternet==0) || (bFlagHostResolved==0) || (bFlagServerHello==0), MyLanIP will be "0.0.0.0"
	RT_APP_CHAR MyWanIP[16];		// My Wan IP. If (bFlagInternet==0) || (bFlagHostResolved==0) || (bFlagServerHello==0), MyWanIP will be "0.0.0.0"
}RT_APP_NETWORK_Info;

/*app需要初始化的回调函数结构体*/
typedef struct _RT_APP_Params_s 
{
	RT_APP_INT32 (*setMsgReturnCallBack)(const RT_APP_CHAR *uid, RT_APP_INT32 msg, RT_APP_CHAR *pbuf, RT_APP_INT32 len);
	RT_APP_INT32 (*getMsgDataCallBack)(const RT_APP_CHAR *uid, RT_APP_INT32 msg, RT_APP_CHAR *pbuf, RT_APP_INT32 len);
	RT_APP_INT32 (*connectStatusCallBack)(const RT_APP_CHAR *uid, RT_APP_INT32 msgType, RT_APP_INT32 msgValue);
	RT_APP_INT32 (*searchDataCallBack)(RT_APP_CHAR *pbuf);
	RT_APP_INT32 (*h264VideoPlayerCallBack)(const RT_APP_CHAR *uid, RT_APP_UCHAR *pbuf, RT_APP_INT32 frametype, RT_APP_UINT32 timestamp, RT_APP_INT32 len, RT_APP_VOID *pOutUserData);
	RT_APP_INT32 (*h264PlayBackCallBack)(const RT_APP_CHAR *uid, RT_APP_UCHAR *pbuf, RT_APP_INT32 frametype, RT_APP_UINT32 timestamp, RT_APP_INT32 len);
	RT_APP_INT32 (*otherVideoPlayerCallBack)(const RT_APP_CHAR *uid, RT_APP_UCHAR *pbuf, RT_APP_INT32 frametype, RT_APP_INT32 len);
	RT_APP_INT32 (*audioPlayerCallBack)(const RT_APP_CHAR *uid, RT_APP_UCHAR *pbuf, RT_APP_INT32 len);
	RT_APP_INT32 (*alarmCallBack)(const RT_APP_CHAR *uid, RT_APP_INT32 alarmType, RT_APP_VOID *pData);
	RT_APP_INT32 (*notifyCallBack)(const RT_APP_CHAR *uid, RT_APP_CHAR *pNotifyJsonData, RT_APP_INT32 notifyJsonLen);
	RT_APP_INT32 (*loadPicCallBack)(const RT_APP_CHAR *uid, const RT_APP_CHAR *pFileName, RT_APP_UCHAR *pbuf, RT_APP_INT32 len, RT_APP_UCHAR endFlag);
	RT_APP_INT32 (*loadVidCallBack)(const RT_APP_CHAR *uid, const RT_APP_CHAR *pFileName, RT_APP_UCHAR *pbuf, RT_APP_INT32 len, RT_APP_UCHAR endFlag);
	RT_APP_INT32  (*funExtCallBack)(RT_APP_CHAR *pWillMatchUid, RT_APP_CHAR *pExtRealUid);
	RT_APP_VOID  (*logCallBack)(RT_APP_INT32 logLevel,const RT_APP_CHAR *format);
}RT_APP_Params;

/*初始化函数,填入参数为回调函数结构体(app运行时调用)*/
RT_APP_INT32 RT_APP_API_Initial(RT_APP_Params *pAppParams);

/*去初始化(app退出时调用)*/
RT_APP_INT32 RT_APP_API_DeInitial();

/*获取当前链路网络信息,一般只有一个链路的时候调用*/
RT_APP_INT32 RT_APP_API_NETWORK_Detect(RT_APP_NETWORK_Info *pNetInfo);

/*连接摄像机,连接状态会通过上述init函数中的状态回调返回*/
RT_APP_INT32 RT_APP_API_Start(RT_APP_UPTR* pu32AppHandle, RT_APP_CHAR *szDID, RT_APP_CHAR *szUser, RT_APP_CHAR *szPwd, RT_APP_VOID *pUserData); //pUserData 由用户输入,从实时码流回调进行返回);

/*断开和摄像机间的链接,并回收线程资源*/
RT_APP_INT32 RT_APP_API_Stop(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*断开上述start接口中正在连接的设备,但还未连接成功的,如果是在线设备此接口无用*/
RT_APP_INT32 RT_APP_API_CONNECT_Break(RT_APP_UPTR u32AppHandle);

/*开启搜索当前网络中摄像机UID,搜索到的结果通过搜索回调返回*/
RT_APP_INT32 RT_APP_API_SEARCH_DEV_Start();

/*停止UID搜索*/
RT_APP_INT32 RT_APP_API_SEARCH_DEV_Stop();

/*开启视频流,传入start返回的handle,及需要开启的哪路视频流的ID,由视频流回调返回视频数据*/
RT_APP_INT32 RT_APP_API_START_LIVE_Stream(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_INT32 streamid);

/*停止视频返回*/
RT_APP_INT32 RT_APP_API_STOP_LIVE_Stream(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*视频流切换,streamid为想切换的码流值,切换前注意先清空原来的视频流buf*/
RT_APP_INT32 RT_APP_API_SWITCH_Stream(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_INT32 streamid);

/*开启音频流,audioFormat为音频流格式,0:pcm 1:aac,音频流由音频回调返回*/
RT_APP_INT32 RT_APP_API_START_Audio(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_UCHAR audioFormat);

/*关闭音频流*/
RT_APP_INT32 RT_APP_API_STOP_Audio(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*开启对讲流,告知摄像机准备接收对讲数据*/
RT_APP_INT32 RT_APP_API_START_Talk(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*告知摄像机停止接收对讲流*/
RT_APP_INT32 RT_APP_API_STOP_Talk(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*待上面start talk流通道后,就调用此接口发送talk流到摄像机端*/
RT_APP_INT32 RT_APP_API_TALK_AUDIO_Data(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_CHAR *pTalkData, RT_APP_INT32 talkLen, RT_APP_INT32 talkFrmType);

/*开启回放请求*/
RT_APP_INT32 RT_APP_API_START_PlayBack(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_CHAR *fileName, RT_APP_INT32 offset);

/*停止回放请求*/
RT_APP_INT32 RT_APP_API_STOP_PlayBack(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID);

/*获取设备端各属性参数,获取的数据有获取回调函数返回*/
RT_APP_INT32 RT_APP_API_GET_SYSTEM_Params(RT_APP_UPTR u32AppHandle, RT_APP_CHAR * szDID, RT_APP_INT32 type, RT_APP_VOID *pData, RT_APP_UINT32 len);

/*设置由app端的参数给摄像机*/
RT_APP_INT32 RT_APP_API_SET_SYSTEM_Params(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_INT32 type, RT_APP_VOID *pData, RT_APP_UINT32 len);

/*开启要下载的文件,pData为下载数据结构体,详情见test.c*/
RT_APP_INT32 RT_APP_API_START_DOWNLOAD_File(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_VOID *pData, RT_APP_INT32 len);

/*停止下载文件,filename为要停止下载的文件名*/
RT_APP_INT32 RT_APP_API_STOP_DOWNLOAD_File(RT_APP_UPTR u32AppHandle, RT_APP_CHAR *szDID, RT_APP_CHAR *pFileName);

RT_APP_INT32 RT_APP_API_WAKEUP_Query(RT_APP_WAKEUP_Query *wakeupQueryInfo,RT_APP_INT32 pOutLastLogin[],RT_APP_INT32 loginNum);

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* End of #ifdef __cplusplus */


#endif //__RT_OBJECT_API_H__

